<script type="text/javascript" src="<?php echo base_url()?>js/back_end/lib.js"></script>
<div id="content-right">
	<div id="add-product">
		<div id="sidebar-list" class="black">
			<div id="img-product" class="left white">
				 <?php echo $title?>
			</div>
			<div id="img-back" class="right">
				<a href="javascript:;" onclick="history.go(-1)" class="white">Quay lại trang trước </a>
			</div>
			<div class="clear"></div>
		</div>
		<form name="AdminPermissions" id="AdminPermissions" action="" method="POST">
			<div id="list-product">
				<table id="myTable" class="tablePr tablesorter" width="100%" border="0" cellspacing="0" cellpadding="0">
					<thead>
						<tr class="headerTbl">
							<td width="5%">STT</td>
							<td width="35%">Tên Menu</td>
							<td width="15%">Truy Cập</td>
							<td width="15%">Thêm</td>
							<td width="15%">Sửa</td>
							<td width="15%">Xóa</td>
						</tr>
						<tr class="headerTbl" align="center">
							<td colspan="2"></td>
							<td>
								<a href="JavaScript:" onclick="JavaScript:PermissionCheckAll('AdminPermissions','Per_',0);"><u>Check All</u></a> | 
								<a href="JavaScript:" onclick="JavaScript:PermissionCheckAll('AdminPermissions','Per_',1);"><u>UnCheck All</u></a>
							</td>							
							<td>
								<a href="JavaScript:" onclick="JavaScript:PermissionCheckAll('AdminPermissions','Post_',0);"><u>Check All</u></a> | 
								<a href="JavaScript:" onclick="JavaScript:PermissionCheckAll('AdminPermissions','Post_',1);"><u>UnCheck All</u></a>
							</td>
							<td>
								<a href="JavaScript:" onclick="JavaScript:PermissionCheckAll('AdminPermissions','Edit_',0);"><u>Check All</u></a> | 
								<a href="JavaScript:" onclick="JavaScript:PermissionCheckAll('AdminPermissions','Edit_',1);"><u>UnCheck All</u></a>
							</td>
							<td>
								<a href="JavaScript:" onclick="JavaScript:PermissionCheckAll('AdminPermissions','Del_',0);"><u>Check All</u></a> | 
								<a href="JavaScript:" onclick="JavaScript:PermissionCheckAll('AdminPermissions','Del_',1);"><u>UnCheck All</u></a>
							</td>
						</tr>
					</thead>
					<?php if (!empty($menu)){?>
						<tbody>
							<?php
								$i = 1;
								foreach ($menu as $m)
								{
									$PerCheck    ="";
									$PostCheck	 ="";
									$EditCheck	 ="";
									$DelCheck	 ="";
									$PostDisable ="";
									$EditDisable ="";
									$DelDisable	 ="";		
									$PerDisable  ="";
									
									$arrWhere = array('menu_admin_id' => $m['id'], 
													  'admin_id' 		=> $admin_id);
									$permisstMenu3 = $this->db->get_where('admin_permiss', $arrWhere);
									if($permisstMenu3->num_rows() > 0)
									{
										foreach($permisstMenu3->result_array() as $permis)
										{
											if ($permis["access"]==1) {$PerCheck="checked";$PerDisable="";}	
											if ($permis["add"]   ==1) $PostCheck="checked";
											if ($permis["edit"]  ==1) $EditCheck="checked";
											if ($permis["del"]   ==1) $DelCheck="checked";		
											if ($PerDisable=="disabled"){$PostDisable="disabled";$EditDisable="disabled";$DelDisable="disabled";}
										}								 								 	
									}
																	
									if ($i % 2 == 0)
									{
										$bgcolor="str1";
									}else{
										$bgcolor="str2";
									}
							?>
								<tr class="<?php echo $bgcolor?>">							
									<td><input type="hidden" name="menu_id_3_<?php echo $m['id'] ?>" value="<?php echo $m['id'] ?>" /><?php echo $i?></td>
									<td><?php echo $m['name']?></td>
									<td><input type="checkbox" name="Per_<?php if (!empty($m['id'])) echo $m['id']?>" value="1" id="Per_<?php echo $m['id']?>" <?php if (!empty($permis['access'])){ if ($permis['access']==1){ echo 'checked';  }} ?>   onClick="JavaScript:CheckBoxPermission(<?php echo $m['id']?>,0);"></td>
									<td><input type="checkbox" name="Post_<?php if (!empty($m['id'])) echo $m['id']?>" id="Post_<?php echo $m['id']?>" value="1" <?php if (!empty($permis['add'])){ if ($permis['add']==1){ echo 'checked'; }} if (!empty($permis['access'])){ if ($permis['access']==0){ echo 'disabled'; }} ?> onClick="JavaScript:CheckBoxPermission(<?php echo $m['id']?>,1);"/></td>
									<td><input type="checkbox" name="Edit_<?php if (!empty($m['id'])) echo $m['id']?>" id="Edit_<?php echo $m['id']?>" value="1" <?php if (!empty($permis['edit'])){ if ($permis['edit']==1){ echo 'checked'; }} if (!empty($permis['access'])){ if ($permis['access']==0){ echo 'disabled'; }}?>  onClick="JavaScript:CheckBoxPermission(<?php echo $m['id']?>,1);"/></td>
									<td><input type="checkbox" name="Del_<?php if (!empty($m['id'])) echo $m['id']?>" id="Del_<?php echo $m['id']?>" value="1" <?php if (!empty($permis['del'])){ if ($permis['del']==1){ echo 'checked'; }} if (!empty($permis['access'])){ if ($permis['access']==0) { echo 'disabled';}} ?>/></td>							
								</tr>						
							<?php $i++;}?>				
							<tr>
								<td colspan="6" align="left">
									<input type="submit" class="submit-product" name="cmd" value="Update" style="color: #FFF; font-weight: bold; padding-bottom: 5px;" />
									<input type="reset" class="reset-product"  value='Cancel' style="color: #FFF; font-weight: bold; padding-bottom: 5px;" />
								</td>
							</tr>
						</tbody>
					<?php }else{?>
						<tr><td colspan="6" style="padding:15px;">Không có dữ liệu</td></tr>
					<?php }?>
				</table>
			</div>
		</form>
	</div>
</div>
<script>
	/*
	var bool = $("input:checkbox");
	for(i = 0; i < bool.length; i++){					
		bool[i].disabled = "disabled";
	}
	bool[0].disabled = "";
	if(bool[0].checked == true){
		for(i = 0; i < bool.length; i++){			
			if(bool[i].name.indexOf('Per') == 0){
				if(bool[i].checked == true){
					for(j = 1; j < 4; j++){
						bool[i+j].disabled = "";
					}
				}
				bool[i].disabled = "";
			}
		}				
	}

	function checkInBoxPermiss(){
		var arrs = new Array();

		for(var x=0; x < document.AdminPermissions.elements.length; x++)
		{
		  if(document.AdminPermissions.elements[x].type == "checkbox")
		  {	  
			  arrs.push(document.AdminPermissions.elements[x]); 
		  }
		}

		var bool = arrs;
		if(bool[0].checked == true){
			for(i = 0; i < bool.length; i++){			
				if(bool[i].name.indexOf('Per') == 0){
					if(bool[i].checked == true){
						for(j = 1; j < 4; j++){
							bool[i+j].disabled = "";
						}
					}else if(bool[i].checked == false){
						for(j = 1; j < 4; j++){
							bool[i+j].disabled = "disabled";
						}
					}
					bool[i].disabled = "";
				}
			}				
		}else{
			for(i = 0; i < bool.length; i++){					
				bool[i].disabled = "disabled";
			}
			bool[0].disabled = "";
		}	
	}
*/
</script>